<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>智能迷宫更新版</title>
<script type="text/javascript" src="jquery-3.2.1.min.js"></script>

</head>

<body style='background:url(bg2.gif)'>


<div id="origin" style="position: absolute;width: 12px;height: 12px;z-index: 2;background-color: red;"></div>
<div id="destination" style="position: absolute;width: 12px;height: 12px;z-index: 1;background-color:lime;top: 746px;left: 746px;"></div>

<div id='pen' style='position:absolute;width:3px;height:3px;background-color:black;'></div>
    
<canvas id="canvas"  width="753" height="753"></canvas>
    
    

<button id='menu' style='height:40px;border-radius:20px;position:fixed;top:5px;right:5px;background-color:#CCFFFF' onClick='$("#controller").slideToggle();'>菜单</button>
    
<div style="float: right;" id="controller">
    
    <button id='language'  style='border-radius:20px' onClick='alert("敬请期待")'>语言:中文(点击切换)</button><br>
    键盘控制：<button onClick="alert('方向键移动，玩家可以随时切换走起点或终点来完成迷宫，笔尖只在制图画墙的时候才能移动。温馨提示：由算法决定，专业竞速模式下从终点开始走可以大大降低游戏难度，当然得到的分数也会相应减少。')">?</button><br>
    <input type="radio" id="move_origin" name="keyboard" disabled>起点
    <input type="radio" id="move_destination" name="keyboard" disabled>终点
    <input type="radio" id="move_pen" name="keyboard" checked>笔尖<br>
    设置颜色：<button onClick="alert('颜色系统是全局控制台，可以任意时刻改变这5个元素的颜色。有三种颜色的书写方法，第一种：常用颜色的英文名称，总共150+种；第二种：颜色的十六进制格式，如#987abc；第三种：RGB格式；详情请参见《Web颜色对照表》。')">?</button><br>
    背景：<input type="text" id="canvas_color" value=""><br>
    起点：<input type="text" id="origin_color" value="red"><br>
    终点：<input type="text" id="destination_color" value="lime"><br>
    墙体：<input type="text" id="wall_color" value="black"><br>
    路径：<input type="text" id="path_color" value="yellow"><br>
    沿途记录：<input type="checkbox" id="record" ><button onClick="alert('对应上面的路径颜色，用颜色记录沿途走过的路程可以一定程度帮助你顺利通关。您的新技能：单击地图上的路径可以瞬间移动到那个位置！')">?</button><br>
    <button id="paint" onClick="paint()" style="font-size: 1em;border:5px inset">重新制图</button><br>
    坐标(x,y)：<button onClick="alert('作者为玩家提供的虚拟坐标，地图上每一个方块都是单位1，从左上角向右下角递增。其中起点和终点必须是正整数，而笔尖的位置必须是.5的小数,图上的一个小点(和墙同色)就是笔尖的位置')">?</button><br>
    起点：<input type="number" id="ori_x" value="1" min="1" max="50" step="1" onChange="ori_x_cha()">
    <input type="number" id="ori_y" value="1" min="1" max="50" step="1" onChange="ori_y_cha()"><br>
    终点：<input type="number" id="des_x" value="50" min="1" max="50" step="1" onChange="des_x_cha()">
    <input type="number" id="des_y" value="50" min="1" max="50" step="1" onChange="des_y_cha()"><br>
    笔尖：<input type="number" id="pen_x" value="0.5" min="0.5" max="50.5" step="1" onChange='pen_x_change()'>
    <input type="number" id="pen_y" value="0.5" min="0.5" max="50.5" step="1" onChange='pen_y_change()'><br>
    地图设置：<button onClick="alert('这里设置地图的尺寸和大小，注意两者的区别。其中尺寸的单位是像素而数量是整数，对应着虚拟坐标')">?</button><br>
    墙体厚度：<input type="number" min="1" max="10" step="1"  value="3" id="wall_size"><br> 
    方块边长：<input type="number" min="1" max="50" step="1"  value="12" id="square_size"><br>
    水平数量：<input type="number" min="1" max="99" step="1"  value="50" id="amount_x"><br>
    垂直数量：<input type="number" min="1" max="99" step="1"  value="50" id="amount_y"><br>
    请选择迷宫生成算法：<button onClick="alert('智商高于87.5请选择专业竞速:D;温馨提示：有可能遇到兼容性问题,可以多次点击专业竞速以生成完整地图,弱智模式下连续点击会更简单')">?</button><br>
    &gt;&gt;&gt;<button id="generate" onClick="generate()" style="font-size: 1em;border:5px outset ;">弱智模式</button>
    <button id="advanced_generate" onClick="advanced_generate()" style="font-size: 1em;border:5px outset ;">专业竞速</button>&lt;&lt;&lt;<br>
    背景音乐：<select id='musicList'>
	<option>battle</option>
	<option>kanoon</option>
	<option>danger</option>
	<select><br>
    <audio id='musicController' autoplay loop controls src='battle.mp3'></audio>
</div>
   








<script type="text/javascript">

        alert("版本14.0预告：更新以下内容。\n1.设计得分系统\n2.加入\"冲刺\"技能\n3.修复数字小数格式补丁\n4.笔尖瞬移技能\n5.本地存储功能");


	var wall=new Array();
	var shortest_path=new Array();
	
	
	var wall_size=3;
	var square_size=12;
    var amount_x=50;
	var amount_y=50;
	
	
	var direction=new Array();
	var already_path=new Array();
	
	var state="draw";
	var get;
	var language='chinese';






	
window.onload=function(){
	
	var wall_color=document.getElementById("wall_color");
	var path_color=document.getElementById("path_color");
    var origin=document.getElementById("origin");
	var destination=document.getElementById("destination");
	var pen_x=document.getElementById("pen_x");
	var pen_y=document.getElementById("pen_y");
	var ori_x=document.getElementById("ori_x");
	var ori_y=document.getElementById("ori_y");
	var des_x=document.getElementById("des_x");
	var des_y=document.getElementById("des_y");
    var canvas=document.getElementById("canvas");
	




$("#menu").hover(function(){
    $(this).css("background-color","#FFCCCC");
    },function(){
    $(this).css("background-color","#CCFFFF");
  });




	
	
    document.getElementById("canvas_color").onchange=function(){
	    canvas.style.backgroundColor=this.value;
    }


    document.getElementById("origin_color").onchange=function(){
	    origin.style.backgroundColor=this.value;
    }
	
	
	document.getElementById("destination_color").onchange=function(){
	    destination.style.backgroundColor=this.value;
	}

	
	
	
	wall_color.onchange=function(){
		for(var i=0;i<=amount_x;i++)
			for(var j=0;j<=amount_y;j++)
				{
					if(wall[i][j].right==1)draw_wall(i+0.5,j);
					if(wall[i][j].down==1)draw_wall(i,j+0.5);
				}
		$('#pen').css({'background-color':wall_color.value});
	}
	
	
	
	
	path_color.onchange=function(){
		for(var i=1;i<=amount_x;i++)
			for(var j=1;j<=amount_y;j++)
				if(already_path[i][j]==1)draw_path(i,j);
	
	}
	
	
	
	
	canvas.onclick=function(event){
		
		
		if((event.clientX-canvas.offsetLeft-wall_size)%(wall_size-(-square_size))<=square_size){
			if((event.clientY-canvas.offsetTop-wall_size)%(wall_size-(-square_size))<=square_size){
				if(already_path[Math.ceil((event.clientX-canvas.offsetLeft-wall_size)/(wall_size-(-square_size)))][Math.ceil((event.clientY-canvas.offsetTop-wall_size)/(wall_size-(-square_size)))]==1){
					if(document.getElementById("move_origin").checked){
				ori_x.value=Math.ceil((event.clientX-canvas.offsetLeft-wall_size)/(wall_size-(-square_size)));
				ori_x_cha();
				ori_y.value=Math.ceil((event.clientY-canvas.offsetTop-wall_size)/(wall_size-(-square_size)));
                ori_y_cha();
			        }
			        else{
				des_x.value=Math.ceil((event.clientX-canvas.offsetLeft-wall_size)/(wall_size-(-square_size)));
				des_x_cha();
				des_y.value=Math.ceil((event.clientY-canvas.offsetTop-wall_size)/(wall_size-(-square_size)));
                des_y_cha();
			        }
				}
			}
        }	
	}
	
	
	
		
	
	
	
	
	document.getElementById("wall_size").onchange=function(){
		wall_size=parseInt(this.value);
		canvas.width=0;
		canvas.height=0;
		set_canvas_size();
		$('#pen').css({'width':wall_size+'px','height':wall_size+'px'});
		for(var i=0;i<=amount_x;i++)
			for(var j=0;j<=amount_y;j++){
				if(wall[i][j].right==1)draw_wall(i+0.5,j);
				if(wall[i][j].down==1)draw_wall(i,j+0.5);
			}
		set_origin_position();
		set_destination_position();
		set_pen_position();
	}
	
	
	
	
	
	document.getElementById("square_size").onchange=function(){
		square_size=parseInt(this.value);
		canvas.width=0;
		canvas.height=0;
		set_canvas_size();
		for(var i=0;i<=amount_x;i++)
			for(var j=0;j<=amount_y;j++){
				if(wall[i][j].right==1)draw_wall(i+0.5,j);
				if(wall[i][j].down==1)draw_wall(i,j+0.5);
			}
		
		origin.style.width=square_size+"px";
		origin.style.height=square_size+"px";
		destination.style.width=square_size+"px";
		destination.style.height=square_size+"px";		
		set_origin_position();
		set_destination_position();
	}
	
	
	
	
	
	
	
	
	
	document.getElementById("amount_x").onchange=function amo_x_cha(){
		amount_x=parseInt(this.value);
		set_canvas_size();
		clear_canvas();
		draw_border_wall();
		ori_x.max=amount_x;
		ori_x.value=1;
		ori_y.value=1;
		des_x.max=amount_x;
		des_x.value=amount_x;
	    des_y.value=amount_y;
		pen_x.max=amount_x;
		pen_x.value=0.5;
		pen_y.value=0.5;
		ori_x_cha();ori_y_cha();des_x_cha();des_y_cha(); 
		set_pen_position();
	}
	
	
	
	
	
	
	
	
	document.getElementById("amount_y").onchange=function amo_y_cha(){
		amount_y=parseInt(this.value);
		set_canvas_size();
		clear_canvas();
		draw_border_wall();
		ori_y.max=amount_y;
		ori_x.value=1;
		ori_y.value=1;
		des_y.max=amount_y;
		des_x.value=amount_x;
	    des_y.value=amount_y;
		pen_y.max=amount_y;
	    pen_x.value=0.5;
		pen_y.value=0.5;
		ori_x_cha();ori_y_cha();des_x_cha();des_y_cha();
		set_pen_position();	
	}
	
	
	
//初始化初始化初始化初始化初始化初始化初始化初始化初始化初始化初始化初始化初始化初始化初始化初始化
	
	
	for(var i=0;i<=100;i++){
			wall[i]=new Array();
			for(var j=0;j<=100;j++)
				wall[i][j]=new Object();
		}
	
    
	for(var i=1;i<=100;i++){
			already_path[i]=new Array();
		}
	clear_already();
	    
	draw_border_wall();
    
	
	origin.style.top=canvas.offsetTop-(-wall_size)+"px";
	origin.style.left=canvas.offsetLeft-(-wall_size)+"px";	
	$('#point').css({'top':canvas.offsetTop,'left':canvas.offsetLeft});
	
	

	
//初始化初始化初始化初始化初始化初始化初始化初始化初始化初始化初始化初始化初始化初始化初始化初始化
	
	
	
	
}
	




	$('#musicList').change(function(){
	switch($(this).val()){
		case 'kanoon':$('#musicController').attr('src','kanoon.mp3');break;
		case 'battle':$('#musicController').attr('src','battle.mp3');break;
		case 'danger':$('#musicController').attr('src','danger.mp3');break;
		default:break;
	}
});









    $('#language').click(function(){
	if (language=='chinese'){
		$(this).text('language:English(click2toggle)');
		language='english';
		
	}
	else{
		$(this).text('语言:简体中文(点击切换)')
		language='chinese';
	}
	}
    )






    function ori_x_cha(){
		set_origin_position();
	}
	
	
	function ori_y_cha(){
        set_origin_position();
	}
	
	
	
	
	
	function des_x_cha(){
        set_destination_position();
	}
	
	
	function des_y_cha(){
        set_destination_position();
	}
	
	



        function pen_x_change(){
	set_pen_position();
	}

	function pen_y_change(){
	set_pen_position();
	}






    function set_canvas_size(){
		canvas.width=amount_x*square_size+(amount_x+1)*wall_size;
		canvas.height=amount_y*square_size+(amount_y+1)*wall_size;

	}







    function set_origin_position(){
		origin.style.left=(canvas.offsetLeft+(parseInt(ori_x.value)-1)*square_size+parseInt(ori_x.value)*wall_size)+"px";
		origin.style.top=(canvas.offsetTop+(parseInt(ori_y.value)-1)*square_size+parseInt(ori_y.value)*wall_size)+"px";
	}
	
	
	
	function set_destination_position(){
		destination.style.left=(canvas.offsetLeft+(parseInt(des_x.value)-1)*square_size+parseInt(des_x.value)*wall_size)+"px";
		destination.style.top=(canvas.offsetTop+(parseInt(des_y.value)-1)*square_size+parseInt(des_y.value)*wall_size)+"px";
	}

	function set_pen_position(){
		$('#pen').css({'left':(canvas.offsetLeft+(parseInt(pen_x.value))*square_size+parseInt(pen_x.value)*wall_size)+"px",'top':(canvas.offsetTop+(parseInt(pen_y.value))*square_size+parseInt(pen_y.value)*wall_size)+"px"})
	}



	
	
    function clear_canvas(){
		var ctx=canvas.getContext("2d");
		ctx.clearRect(0,0,amount_x*square_size+(amount_x+1)*wall_size,amount_y*square_size+(amount_y+1)*wall_size);
		for(var i=0;i<=amount_x;i++)
			for(var j=0;j<=amount_y;j++){
				wall[i][j].right=0;
				wall[i][j].down=0;
			}
		for(var i=1;i<=amount_x;i++)
			for(var j=1;j<=amount_y;j++)
				already_path[i][j]=0;
	}
	
	
	
	


    function draw_border_wall(){
		for(var i=1;i<=amount_x;i++){
            draw_wall(i,0.5);draw_wall(i,amount_y+0.5);
		}
		for(var i=1;i<=amount_y;i++){
			draw_wall(0.5,i);draw_wall(amount_x+0.5,i);
		}
	}
	
	
	
	
	



    function paint(){
		clear_canvas();
		draw_border_wall();
		document.getElementById("generate").removeAttribute("disabled");
		document.getElementById("advanced_generate").removeAttribute("disabled");
        document.getElementById("move_origin").disabled="true";
		document.getElementById("move_destination").disabled="true";
		ori_x.removeAttribute("disabled");
		ori_y.removeAttribute("disabled");
		des_x.removeAttribute("disabled");
		des_y.removeAttribute("disabled");
		document.getElementById("move_pen").removeAttribute("disabled");
		pen_x.removeAttribute("disabled");
		pen_y.removeAttribute("disabled");
		document.getElementById("wall_size").removeAttribute("disabled");
		document.getElementById("square_size").removeAttribute("disabled");
		document.getElementById("amount_x").removeAttribute("disabled");
		document.getElementById("amount_y").removeAttribute("disabled");
		document.getElementById("move_pen").checked="true";
        state="draw";
	}


    
	
	
	
	
	
	function generate(){	
        if(state=="play"){random_draw_wall();return null;}
				state="play";
		clear_already();
		document.getElementById("advanced_generate").disabled="true";
		ori_x.disabled="true";
		ori_y.disabled="true";
		des_x.disabled="true";
		des_y.disabled="true";
		document.getElementById("move_pen").disabled="true";
		pen_x.disabled="true";
		pen_y.disabled="true";
		document.getElementById("wall_size").disabled="true";
		document.getElementById("square_size").disabled="true";
		document.getElementById("amount_x").disabled="true";
		document.getElementById("amount_y").disabled="true";
		document.getElementById("move_origin").removeAttribute("disabled");
		document.getElementById("move_destination").removeAttribute("disabled");
		document.getElementById("move_origin").checked="true";
        shortest_path.length=0;
		shortest_path[0]=new Object();
		shortest_path[0].x=parseInt(ori_x.value);
		shortest_path[0].y=parseInt(ori_y.value);
		already_path[parseInt(ori_x.value)][parseInt(ori_y.value)]=1;

		run();
		random_draw_wall();
		clear_already();
}
	
	
	
	function advanced_generate(){
						state="play";
        clear_already();
		document.getElementById("generate").disabled="true";
		ori_x.disabled="true";
		ori_y.disabled="true";
		des_x.disabled="true";
		des_y.disabled="true";
		document.getElementById("move_pen").disabled="true";
		pen_x.disabled="true";
		pen_y.disabled="true";
		document.getElementById("wall_size").disabled="true";
		document.getElementById("square_size").disabled="true";
		document.getElementById("amount_x").disabled="true";
		document.getElementById("amount_y").disabled="true";
		document.getElementById("move_origin").removeAttribute("disabled");
		document.getElementById("move_destination").removeAttribute("disabled");
		document.getElementById("move_origin").checked="true";
		shortest_path.length=0;
		shortest_path[0]=new Object();
		shortest_path[0].x=parseInt(des_x.value);
		shortest_path[0].y=parseInt(des_y.value);
		already_path[parseInt(des_x.value)][parseInt(des_y.value)]=1;
		get="no";
		advanced_run();
		if(get!="yes")alert("亲，请检查起点和终点是否被墙残忍地分隔异地，or小编无法为您设计迷宫哦！");
		clear_already();
	}
	
    





    function draw_wall(x,y){
		var ctx=canvas.getContext("2d");
		ctx.fillStyle=wall_color.value;
		if(x%1==0&&y%1==0.5){
			ctx.fillRect((x-1)*square_size+x*wall_size,parseInt(y)*(square_size+wall_size),square_size,wall_size);
			wall[x][y-0.5].down=1;
		}
		if(x%1==0.5&&y%1==0){
			ctx.fillRect(parseInt(x)*(square_size+wall_size),(y-1)*square_size+y*wall_size,wall_size,square_size);
			wall[x-0.5][y].right=1;
		}
	}
	
	
	
	
	
	
	function draw_path(x,y){
		var ctx=canvas.getContext("2d");
		ctx.fillStyle=path_color.value;
		if(x%1==0&&y%1==0){
			ctx.fillRect((x-1)*square_size+x*wall_size,(y-1)*square_size+y*wall_size,square_size,square_size);
		}
		already_path[x][y]=1;
	}
	
	
	function clear_path(x,y){
		var ctx=canvas.getContext("2d");
		if(x%1==0&&y%1==0){
			ctx.clearRect((x-1)*square_size+x*wall_size,(y-1)*square_size+y*wall_size,square_size,square_size);
		}
		already_path[x][y]=0;
	}
	
	
	

	
	
	
	
	
	
	
	function clear_already(){
		
		for(var i=1;i<=amount_x;i++)
			for(var j=1;j<=amount_y;j++)
				if(already_path[i][j]==1)clear_path(i,j);
	}
	
	
	
	
	
	
	document.body.onkeydown=function(key){
        if(document.getElementById("move_origin").checked){
			if(document.getElementById("record").checked)
			    draw_path(parseInt(ori_x.value),parseInt(ori_y.value));
			switch(key.keyCode){
				case 37:if(wall[parseInt(ori_x.value)-1][parseInt(ori_y.value)].right%2==0){
					ori_x.value--;
					ori_x_cha();
				}break;
				case 38:if(wall[parseInt(ori_x.value)][parseInt(ori_y.value)-1].down%2==0){
					ori_y.value--;
					ori_y_cha();
				}break;
				case 39:if(wall[parseInt(ori_x.value)][parseInt(ori_y.value)].right%2==0){
					ori_x.value++;
					ori_x_cha();
				}break;
				case 40:if(wall[parseInt(ori_x.value)][parseInt(ori_y.value)].down%2==0){
					ori_y.value++;
					ori_y_cha();
				}break;
				default:break;
			}
			if(parseInt(ori_x.value)==parseInt(des_x.value)&&parseInt(ori_y.value)==parseInt(des_y.value))
				alert("you win!");
			
		}
		if(document.getElementById("move_destination").checked){
			if(document.getElementById("record").checked)
			    draw_path(parseInt(des_x.value),parseInt(des_y.value));
			switch(key.keyCode){
				case 37:if(wall[parseInt(des_x.value)-1][parseInt(des_y.value)].right%2==0){
					des_x.value--;
					des_x_cha();
				}break;
				case 38:if(wall[parseInt(des_x.value)][parseInt(des_y.value)-1].down%2==0){
					des_y.value--;
					des_y_cha();
				}break;
				case 39:if(wall[parseInt(des_x.value)][parseInt(des_y.value)].right%2==0){
					des_x.value++;
					des_x_cha();
				}break;
				case 40:if(wall[parseInt(des_x.value)][parseInt(des_y.value)].down%2==0){
					des_y.value++;
					des_y_cha();
				}break;
				default:break;
			}
			if(parseInt(ori_x.value)==parseInt(des_x.value)&&parseInt(ori_y.value)==parseInt(des_y.value))
				alert("you win!");
		}
		if(document.getElementById("move_pen").checked){
			switch(key.keyCode){
				case 37:if(pen_x.value>=1.5){draw_wall(pen_x.value-0.5,pen_y.value);--pen_x.value;}break;
				case 38:if(pen_y.value>=1.5){draw_wall(pen_x.value,pen_y.value-0.5);--pen_y.value;}break;
				case 39:if(pen_x.value<=amount_x-0.5){draw_wall(pen_x.value-(-0.5),pen_y.value);++pen_x.value;}break;
				case 40:if(pen_y.value<=amount_y-0.5){draw_wall(pen_x.value,pen_y.value-(-0.5));++pen_y.value;}break;
				default:break;
			}
			set_pen_position();
		}
	}
	
	
	
	
	
	function run(){
		
		if(shortest_path.length==0){
			alert("亲，请检查起点和终点是否被墙残忍地分隔异地，or小编无法为您设计迷宫哦！");return null;
		}
		if(shortest_path[shortest_path.length-1].x==parseInt(des_x.value)&&shortest_path[shortest_path.length-1].y==parseInt(des_y.value))return null;
		look_around();
				var t=shortest_path.length;		
		if(direction.length==0){
			shortest_path.pop();
			run();
		}
		else {		        shortest_path[t]=new Object();
          switch(direction[parseInt(direction.length*Math.random())]){
			case 37:shortest_path[t].x=shortest_path[t-1].x-1;shortest_path[t].y=shortest_path[t-1].y;already_path[shortest_path[t].x][shortest_path[t].y]=1;break;
			case 38:shortest_path[t].x=shortest_path[t-1].x;shortest_path[t].y=shortest_path[t-1].y-1;already_path[shortest_path[t].x][shortest_path[t].y]=1;break;
			case 39:shortest_path[t].x=shortest_path[t-1].x+1;shortest_path[t].y=shortest_path[t-1].y;already_path[shortest_path[t].x][shortest_path[t].y]=1;break;
			case 40:shortest_path[t].x=shortest_path[t-1].x;shortest_path[t].y=shortest_path[t-1].y+1;already_path[shortest_path[t].x][shortest_path[t].y]=1;break;
			default:break;
		}run();}
	}
	
	
	
	
	
	
	function advanced_run(){
		if(shortest_path.length==0){
			return null;
		}
		look_around();
		var t=shortest_path.length;
		if(direction.length==0){
			shortest_path.pop();advanced_run();
		}
		else{
			for(var i=0;i<direction.length;i++){
				switch(direction[i]){
					case 37:draw_wall(shortest_path[t-1].x-0.5,shortest_path[t-1].y);wall[shortest_path[t-1].x-1][shortest_path[t-1].y].right=3;break;
					case 38:draw_wall(shortest_path[t-1].x,shortest_path[t-1].y-0.5);wall[shortest_path[t-1].x][shortest_path[t-1].y-1].down=3;break;
					case 39:draw_wall(shortest_path[t-1].x+0.5,shortest_path[t-1].y);wall[shortest_path[t-1].x][shortest_path[t-1].y].right=3;break;
					case 40:draw_wall(shortest_path[t-1].x,shortest_path[t-1].y+0.5);wall[shortest_path[t-1].x][shortest_path[t-1].y].down=3;break;
					default:break;
				}
			}
			
					        shortest_path[t]=new Object();
			
			
          switch(direction[parseInt(direction.length*Math.random())]){
			case 37:shortest_path[t].x=shortest_path[t-1].x-1;shortest_path[t].y=shortest_path[t-1].y;already_path[shortest_path[t].x][shortest_path[t].y]=1;break;
			case 38:shortest_path[t].x=shortest_path[t-1].x;shortest_path[t].y=shortest_path[t-1].y-1;already_path[shortest_path[t].x][shortest_path[t].y]=1;break;
			case 39:shortest_path[t].x=shortest_path[t-1].x+1;shortest_path[t].y=shortest_path[t-1].y;already_path[shortest_path[t].x][shortest_path[t].y]=1;break;
			case 40:shortest_path[t].x=shortest_path[t-1].x;shortest_path[t].y=shortest_path[t-1].y+1;already_path[shortest_path[t].x][shortest_path[t].y]=1;break;
			default:break;
		   }
			
			clear_wall((shortest_path[t].x+shortest_path[t-1].x)/2,(shortest_path[t].y+shortest_path[t-1].y)/2);
			
			if(shortest_path[t].x==parseInt(ori_x.value)&&shortest_path[t].y==parseInt(ori_y.value)){
				get="yes";
			}
			advanced_run();
		}
	}
	
	
	
	
	
	function clear_wall(x,y){
		var ctx=canvas.getContext("2d");
        if(x%1==0&&y%1==0.5){
			ctx.clearRect((x-1)*square_size+x*wall_size,parseInt(y)*(square_size+wall_size),square_size,wall_size);
			wall[x][y-0.5].down=0;
		}
		if(x%1==0.5&&y%1==0){
			ctx.clearRect(parseInt(x)*(square_size+wall_size),(y-1)*square_size+y*wall_size,wall_size,square_size);
			wall[x-0.5][y].right=0;
	    }
	
	}
	
	
	function del_array(array,data){
		for(var i=0;i<array.length;i++){
			if(array[i]==data)array.splice(i,1);
		}
	}
	
	
	
	
	
	
	function look_around(){
		direction.length=4;
		direction[0]=37;direction[1]=38;direction[2]=39;direction[3]=40;
		
		if(wall[shortest_path[shortest_path.length-1].x][shortest_path[shortest_path.length-1].y].right==1||already_path[shortest_path[shortest_path.length-1].x+1][shortest_path[shortest_path.length-1].y]==1)del_array(direction,39);
		if(wall[shortest_path[shortest_path.length-1].x][shortest_path[shortest_path.length-1].y].down==1||already_path[shortest_path[shortest_path.length-1].x][shortest_path[shortest_path.length-1].y+1]==1)del_array(direction,40);
		if(wall[shortest_path[shortest_path.length-1].x][shortest_path[shortest_path.length-1].y-1].down==1||already_path[shortest_path[shortest_path.length-1].x][shortest_path[shortest_path.length-1].y-1]==1)del_array(direction,38);
		if(wall[shortest_path[shortest_path.length-1].x-1][shortest_path[shortest_path.length-1].y].right==1||already_path[shortest_path[shortest_path.length-1].x-1][shortest_path[shortest_path.length-1].y]==1)del_array(direction,37);
	}
	
	
	
	
	function random_draw_wall(){
		forbidden_wall();
		for(var i=0;i<=amount_x;i++)
			for(var j=0;j<=amount_y;j++){
				if(wall[i][j].right!=2){
					if(Math.random()>=0.5)draw_wall(i+0.5,j);
				}
				if(wall[i][j].down!=2){
					if(Math.random()>=0.5)draw_wall(i,j+0.5);
				}
			}
	}
	
	
	
	function forbidden_wall(){
		for(var i=1;i<shortest_path.length;i++){
			if(shortest_path[i-1].x==shortest_path[i].x){
				if(shortest_path[i-1].y-1==shortest_path[i].y)
					wall[shortest_path[i].x][shortest_path[i].y].down=2;
				else wall[shortest_path[i-1].x][shortest_path[i-1].y].down=2;
			}
			else {
				if(shortest_path[i-1].x-1==shortest_path[i].x)
					wall[shortest_path[i].x][shortest_path[i].y].right=2;
				else wall[shortest_path[i-1].x][shortest_path[i-1].y].right=2;
			}
		}
	}
	
	
	
	
	
	
</script>






</body>
</html>
